export const preventReClick = {
  inserted: function (el, binding) {
    el.addEventListener('click', () => {
      if (!el.disabled) {
        el.disabled = true
        setTimeout(() => {
          el.disabled = false
        }, binding.value || 1000)
        //binding.value可以自行设置。如果设置了则跟着设置的时间走
        //例如：v-preventReClick='500'
      }
    })
  },
}
//清除行内样式
export const newhtml = {
  inserted: function (el, binding) {
    el.innerHTML = binding.value
      .replace(/&nbsp;/gi, '') //清除空格
      .replace(/\s+style="[^"]*"/g, '') //清除style样式
      .replace(
        /\<img/gi,
        '<img style="max-width: 90%;margin: 10px auto;display: inherit;border: 1px solid #eee;"',
      ) //设置图片class
  },
}
//清除行内样式及图片
export const newhtmlnoimg = {
  inserted: function (el, binding) {
    el.innerHTML = binding.value
      .replace(/&nbsp;/gi, '') //清除空格
      .replace(/\s+style="[^"]*"/g, '') //清除style样式
      .replace(/\<img/gi, '<img style="display: none;"') //设置图片class
  },
}
//单行省略号
export const ellipsis = {
  inserted(el) {
    el.style = `overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;`
  },
}

//输入框清除非法输入
export const clearIpt = {
  update(el, binding) {
    const ele = el.getElementsByTagName('input')[0]
    ele.addEventListener('change', function () {
      let val = ele.value
      let temp = val.toString()
      // temp = temp.replace(/\@/g, '')
      temp = temp.replace(/<[^>]*>|<\/[^>]*>/gm, '')
      ele.value = temp
    })
  },
}
